#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<unordered_map>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
#define lowbit(x) x&(-x)
using namespace std;
const int maxn=3e5+1000;
typedef long long LL;
const int mod=998244353;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL ksm(LL a,LL k){LL res=1;while(k){if(k&1) res=res*a%mod;a=a*a%mod;k>>=1;}return res;}
unordered_map<LL,LL>map1;
LL a[maxn],c[maxn],n;
LL tree[maxn],pow2[maxn];
void add(LL x,LL d){
    while(x<=n){
        tree[x]+=d;
        tree[x]%=mod;
        x+=lowbit(x);
    }
}
LL query(LL x){
    LL ans=0;
    while(x>0){
        ans+=tree[x];ans%=mod;
        x-=lowbit(x);
    }return ans;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],c[i]=a[i];
    sort(c+1,c+1+n);
    for(int i=1;i<=n;i++) map1[c[i]]=i;
    pow2[0]=1;
    for(int i=1;i<=n+10;i++) pow2[i]=pow2[i-1]*2%mod;
    LL ans=0;
    for(int i=1;i<=n;i++) add(map1[a[i]],pow2[i]);
    for(int i=1;i<=n;i++){
        add(map1[a[i]],-pow2[i]+mod);
        ans+=((query(n)-query(map1[a[i]]-1)+mod)%mod)*ksm(pow2[i+1],mod-2)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
   	return 0;
}
